package com.rocksea.app.tasks;

import android.os.AsyncTask;
import com.rocksea.app.db.DbCenter;
import com.rocksea.app.db.history.HistoryTable;
import com.rocksea.app.interfaces.MyExecuteCallBack;

import java.util.List;

/**
 * Created by 吴志华 on 2017/10/26.
 *
 * @FileName:com.rocksea.app.tasks.AskInfoTask.java
 */

public class AskInfoTask<T> extends AsyncTask<Void,Void,T> {

    private String baseInfoId;

    private MyExecuteCallBack<T> callBack;

    public AskInfoTask(String baseInfoId, MyExecuteCallBack<T> callBack)
    {
        this.baseInfoId = baseInfoId;
        this.callBack = callBack;
    }
    @Override
    protected T doInBackground(Void... params)
    {
        List<HistoryTable> historyTables = DbCenter.mHistoryDbHelper.queryByBaseInfoId(baseInfoId);
        if (historyTables.size()==0)
            return null;
        switch (historyTables.get(0).getType())
        {
            case HistoryTable.TEST_DY:
                return (T) DbCenter.mDyDbHelper.queryAllLowStarinData(baseInfoId);
            case HistoryTable.TEST_GY:
                return (T) DbCenter.mGyDbHelper.queryByBaseInfoId(baseInfoId);
            case HistoryTable.TEST_JZ:
                break;
            case HistoryTable.TEST_SC:
                return (T) DbCenter.mScDbHelper.queryByBaseInfoId(baseInfoId);
        }
        return null;
    }
    @Override
    protected void onPostExecute(T t)
    {
        super.onPostExecute(t);
        if (t==null)
            callBack.onError(-99,"未查询到数据或数据不完整");
        else
            callBack.onSuccess(t);
    }
}
